/* SPDX-License-Identifier: LGPL-2.1-only */
/*
 * Author: Weijie Gao <hackpascal@gmail.com>
 *
 * SPI-NOR flash SFDP definitions
 */
#pragma once

#ifndef _UFPROG_SPI_NOR_SFDP_H_
#define _UFPROG_SPI_NOR_SFDP_H_

#include <stdint.h>
#include <ufprog/bits.h>

#define SFDP_SIGNATURE						0x50444653

#define SFDP_PARAM_ID_MSB_JEDEC					0xff
#define SFDP_PARAM_ID_LSB_JEDEC_BFPT				0x00
#define SFDP_PARAM_ID_LSB_JEDEC_SMPT				0x81
#define SFDP_PARAM_ID_LSB_JEDEC_4BAIT				0x84
#define SFDP_PARAM_ID_LSB_JEDEC_SCCRM				0x87

#define SFDP_REV_MINOR_A					5
#define SFDP_REV_MINOR_B					6
#define SFDP_REV_MINOR_C					7
#define SFDP_REV_MINOR_D					8
#define SFDP_REV_MINOR_E					9
#define SFDP_REV_MINOR_F					10

struct sfdp_header {
	uint32_t signature;
	uint8_t minor_ver;
	uint8_t major_ver;
	uint8_t nph;
	uint8_t acc_proto;
};

struct sfdp_param_header {
	uint8_t id_lsb;
	uint8_t minor_ver;
	uint8_t major_ver;
	uint8_t len;
	uint8_t ptr[3];
	uint8_t id_msb;
};

#define SFDP_DWORD(i)						((i) - 1)

/* Basic Flash Parameter Table DWORD 1 */
#define BFPT_DW1_SUPPORT_1S_1S_4S_FAST_READ			BIT(22)
#define BFPT_DW1_SUPPORT_1S_4S_4S_FAST_READ			BIT(21)
#define BFPT_DW1_SUPPORT_1S_2S_2S_FAST_READ			BIT(20)
#define BFPT_DW1_SUPPORT_DTR					BIT(19)
#define BFPT_DW1_ADDRESS_BYTES_S				17
#define BFPT_DW1_ADDRESS_BYTES_M				BITS(18, BFPT_DW1_ADDRESS_BYTES_S)
#define BFPT_DW1_SUPPORT_1S_1S_2S_FAST_READ			BIT(16)
#define BFPT_DW1_4K_ERASE_OPCODE_S				8
#define BFPT_DW1_4K_ERASE_OPCODE_M				BITS(15, BFPT_DW1_4K_ERASE_OPCODE_S)
#define BFPT_DW1_VOLATILE_SR_WREN_SEL				BIT(4)
#define BFPT_DW1_VOLATILE_SR_BP_BITS				BIT(3)
#define BFPT_DW1_WRITE_GRANULARITY				BIT(2)
#define BFPT_DW1_BLK_SECT_ERASE_SIZE_S				0
#define BFPT_DW1_BLK_SECT_ERASE_SIZE_M				BITS(1, BFPT_DW1_BLK_SECT_ERASE_SIZE_S)

/* DWORD1 Address Bytes */
#define BFPT_DW1_ADDRESS_BYTES_3				0
#define BFPT_DW1_ADDRESS_BYTES_3_OR_4				1
#define BFPT_DW1_ADDRESS_BYTES_4				2

/* Basic Flash Parameter Table DWORD 2 */
#define BFPT_DW2_FLASH_SIZE_4G_ABOVE				BIT(31)
#define BFPT_DW2_FLASH_SIZE_S					0
#define BFPT_DW2_FLASH_SIZE_M					BITS(30, BFPT_DW2_FLASH_SIZE_S)

/* Basic Flash Parameter Table DWORD 3 */
#define BFPT_DW3_1S_1S_4S_FAST_READ_OPCODE_S			24
#define BFPT_DW3_1S_1S_4S_FAST_READ_OPCODE_M			BITS(31, BFPT_DW3_1S_1S_4S_FAST_READ_OPCODE_S)
#define BFPT_DW3_1S_1S_4S_FAST_READ_MODE_CLKS_S			21
#define BFPT_DW3_1S_1S_4S_FAST_READ_MODE_CLKS_M			BITS(23, BFPT_DW3_1S_1S_4S_FAST_READ_MODE_CLKS_S)
#define BFPT_DW3_1S_1S_4S_FAST_READ_DUMMY_CLKS_S		16
#define BFPT_DW3_1S_1S_4S_FAST_READ_DUMMY_CLKS_M		BITS(20, BFPT_DW3_1S_1S_4S_FAST_READ_DUMMY_CLKS_S)
#define BFPT_DW3_1S_4S_4S_FAST_READ_OPCODE_S			8
#define BFPT_DW3_1S_4S_4S_FAST_READ_OPCODE_M			BITS(15, BFPT_DW3_1S_4S_4S_FAST_READ_OPCODE_S)
#define BFPT_DW3_1S_4S_4S_FAST_READ_MODE_CLKS_S			5
#define BFPT_DW3_1S_4S_4S_FAST_READ_MODE_CLKS_M			BITS(7, BFPT_DW3_1S_4S_4S_FAST_READ_MODE_CLKS_S)
#define BFPT_DW3_1S_4S_4S_FAST_READ_DUMMY_CLKS_S		0
#define BFPT_DW3_1S_4S_4S_FAST_READ_DUMMY_CLKS_M		BITS(4, BFPT_DW3_1S_4S_4S_FAST_READ_DUMMY_CLKS_S)

/* Basic Flash Parameter Table DWORD 4 */
#define BFPT_DW4_1S_2S_2S_FAST_READ_OPCODE_S			24
#define BFPT_DW4_1S_2S_2S_FAST_READ_OPCODE_M			BITS(31, BFPT_DW4_1S_2S_2S_FAST_READ_OPCODE_S)
#define BFPT_DW4_1S_2S_2S_FAST_READ_MODE_CLKS_S			21
#define BFPT_DW4_1S_2S_2S_FAST_READ_MODE_CLKS_M			BITS(23, BFPT_DW4_1S_2S_2S_FAST_READ_MODE_CLKS_S)
#define BFPT_DW4_1S_2S_2S_FAST_READ_DUMMY_CLKS_S		16
#define BFPT_DW4_1S_2S_2S_FAST_READ_DUMMY_CLKS_M		BITS(20, BFPT_DW4_1S_2S_2S_FAST_READ_DUMMY_CLKS_S)
#define BFPT_DW4_1S_1S_2S_FAST_READ_OPCODE_S			8
#define BFPT_DW4_1S_1S_2S_FAST_READ_OPCODE_M			BITS(15, BFPT_DW4_1S_1S_2S_FAST_READ_OPCODE_S)
#define BFPT_DW4_1S_1S_2S_FAST_READ_MODE_CLKS_S			5
#define BFPT_DW4_1S_1S_2S_FAST_READ_MODE_CLKS_M			BITS(7, BFPT_DW4_1S_1S_2S_FAST_READ_MODE_CLKS_S)
#define BFPT_DW4_1S_1S_2S_FAST_READ_DUMMY_CLKS_S		0
#define BFPT_DW4_1S_1S_2S_FAST_READ_DUMMY_CLKS_M		BITS(4, BFPT_DW4_1S_1S_2S_FAST_READ_DUMMY_CLKS_S)

/* Basic Flash Parameter Table DWORD 5 */
#define BFPT_DW5_SUPPORT_4S_4S_4S_FAST_READ			BIT(4)
#define BFPT_DW5_SUPPORT_2S_2S_2S_FAST_READ			BIT(0)

/* Basic Flash Parameter Table DWORD 6 */
#define BFPT_DW6_2S_2S_2S_FAST_READ_OPCODE_S			24
#define BFPT_DW6_2S_2S_2S_FAST_READ_OPCODE_M			BITS(31, BFPT_DW6_2S_2S_2S_FAST_READ_OPCODE_S)
#define BFPT_DW6_2S_2S_2S_FAST_READ_MODE_CLKS_S			21
#define BFPT_DW6_2S_2S_2S_FAST_READ_MODE_CLKS_M			BITS(23, BFPT_DW6_2S_2S_2S_FAST_READ_MODE_CLKS_S)
#define BFPT_DW6_2S_2S_2S_FAST_READ_DUMMY_CLKS_S		16
#define BFPT_DW6_2S_2S_2S_FAST_READ_DUMMY_CLKS_M		BITS(20, BFPT_DW6_2S_2S_2S_FAST_READ_DUMMY_CLKS_S)

/* Basic Flash Parameter Table DWORD 7 */
#define BFPT_DW7_4S_4S_4S_FAST_READ_OPCODE_S			24
#define BFPT_DW7_4S_4S_4S_FAST_READ_OPCODE_M			BITS(31, BFPT_DW7_4S_4S_4S_FAST_READ_OPCODE_S)
#define BFPT_DW7_4S_4S_4S_FAST_READ_MODE_CLKS_S			21
#define BFPT_DW7_4S_4S_4S_FAST_READ_MODE_CLKS_M			BITS(23, BFPT_DW7_4S_4S_4S_FAST_READ_MODE_CLKS_S)
#define BFPT_DW7_4S_4S_4S_FAST_READ_DUMMY_CLKS_S		16
#define BFPT_DW7_4S_4S_4S_FAST_READ_DUMMY_CLKS_M		BITS(20, BFPT_DW7_4S_4S_4S_FAST_READ_DUMMY_CLKS_S)

/* Basic Flash Parameter Table DWORD 8 */
#define BFPT_DW8_ERASE_TYPE2_OPCODE_S				24
#define BFPT_DW8_ERASE_TYPE2_OPCODE_M				BITS(31, BFPT_DW8_ERASE_TYPE2_OPCODE_S)
#define BFPT_DW8_ERASE_TYPE2_SIZE_SHIFT_S			16
#define BFPT_DW8_ERASE_TYPE2_SIZE_SHIFT_M			BITS(23, BFPT_DW8_ERASE_TYPE2_SIZE_SHIFT_S)
#define BFPT_DW8_ERASE_TYPE1_OPCODE_S				8
#define BFPT_DW8_ERASE_TYPE1_OPCODE_M				BITS(15, BFPT_DW8_ERASE_TYPE1_OPCODE_S)
#define BFPT_DW8_ERASE_TYPE1_SIZE_SHIFT_S			0
#define BFPT_DW8_ERASE_TYPE1_SIZE_SHIFT_M			BITS(7, BFPT_DW8_ERASE_TYPE1_SIZE_SHIFT_S)

/* Basic Flash Parameter Table DWORD 9 */
#define BFPT_DW9_ERASE_TYPE4_OPCODE_S				24
#define BFPT_DW9_ERASE_TYPE4_OPCODE_M				BITS(31, BFPT_DW9_ERASE_TYPE4_OPCODE_S)
#define BFPT_DW9_ERASE_TYPE4_SIZE_SHIFT_S			16
#define BFPT_DW9_ERASE_TYPE4_SIZE_SHIFT_M			BITS(23, BFPT_DW9_ERASE_TYPE4_SIZE_SHIFT_S)
#define BFPT_DW9_ERASE_TYPE3_OPCODE_S				8
#define BFPT_DW9_ERASE_TYPE3_OPCODE_M				BITS(15, BFPT_DW9_ERASE_TYPE3_OPCODE_S)
#define BFPT_DW9_ERASE_TYPE3_SIZE_SHIFT_S			0
#define BFPT_DW9_ERASE_TYPE3_SIZE_SHIFT_M			BITS(7, BFPT_DW9_ERASE_TYPE3_SIZE_SHIFT_S)

/* Basic Flash Parameter Table DWORD 10 (Supported since JESD216A) */
#define BFPT_DW10_SECTOR_T4_ERASE_TYP_TIME_UNIT_S		30
#define BFPT_DW10_SECTOR_T4_ERASE_TYP_TIME_UNIT_M		BITS(31, BFPT_DW10_SECTOR_T4_ERASE_TYP_TIME_UNIT_S)
#define BFPT_DW10_SECTOR_T4_ERASE_TYP_TIME_S			25
#define BFPT_DW10_SECTOR_T4_ERASE_TYP_TIME_M			BITS(29, BFPT_DW10_SECTOR_T4_ERASE_TYP_TIME_S)
#define BFPT_DW10_SECTOR_T3_ERASE_TYP_TIME_UNIT_S		23
#define BFPT_DW10_SECTOR_T3_ERASE_TYP_TIME_UNIT_M		BITS(24, BFPT_DW10_SECTOR_T3_ERASE_TYP_TIME_UNIT_S)
#define BFPT_DW10_SECTOR_T3_ERASE_TYP_TIME_S			18
#define BFPT_DW10_SECTOR_T3_ERASE_TYP_TIME_M			BITS(22, BFPT_DW10_SECTOR_T3_ERASE_TYP_TIME_S)
#define BFPT_DW10_SECTOR_T2_ERASE_TYP_TIME_UNIT_S		16
#define BFPT_DW10_SECTOR_T2_ERASE_TYP_TIME_UNIT_M		BITS(17, BFPT_DW10_SECTOR_T2_ERASE_TYP_TIME_UNIT_S)
#define BFPT_DW10_SECTOR_T2_ERASE_TYP_TIME_S			11
#define BFPT_DW10_SECTOR_T2_ERASE_TYP_TIME_M			BITS(15, BFPT_DW10_SECTOR_T2_ERASE_TYP_TIME_S)
#define BFPT_DW10_SECTOR_T1_ERASE_TYP_TIME_UNIT_S		9
#define BFPT_DW10_SECTOR_T1_ERASE_TYP_TIME_UNIT_M		BITS(10, BFPT_DW10_SECTOR_T1_ERASE_TYP_TIME_UNIT_S)
#define BFPT_DW10_SECTOR_T1_ERASE_TYP_TIME_S			4
#define BFPT_DW10_SECTOR_T1_ERASE_TYP_TIME_M			BITS(8, BFPT_DW10_SECTOR_T1_ERASE_TYP_TIME_S)
#define BFPT_DW10_SECTOR_ERASE_MAX_TIME_MULTIPLIER_S		0
#define BFPT_DW10_SECTOR_ERASE_MAX_TIME_MULTIPLIER_M		BITS(3, BFPT_DW10_SECTOR_ERASE_MAX_TIME_MULTIPLIER_S)

/* DWORD10 Sector typical erase time unit */
#define DW10_SECTOR_ERASE_TYP_TIME_UNIT_1MS			0
#define DW10_SECTOR_ERASE_TYP_TIME_UNIT_16MS			1
#define DW10_SECTOR_ERASE_TYP_TIME_UNIT_128MS			2
#define DW10_SECTOR_ERASE_TYP_TIME_UNIT_1S			3

/* Basic Flash Parameter Table DWORD 11 */
#define BFPT_DW11_CHIP_ERASE_TYP_TIME_UNIT_S			29
#define BFPT_DW11_CHIP_ERASE_TYP_TIME_UNIT_M			BITS(30, BFPT_DW11_CHIP_ERASE_TYP_TIME_UNIT_S)
#define BFPT_DW11_CHIP_ERASE_TYP_TIME_S				24
#define BFPT_DW11_CHIP_ERASE_TYP_TIME_M				BITS(28, BFPT_DW11_CHIP_ERASE_TYP_TIME_S)
#define BFPT_DW11_BYTE_PROG_ADD_TYP_TIME_UNIT_S			23
#define BFPT_DW11_BYTE_PROG_ADD_TYP_TIME_UNIT_M			BIT(BFPT_DW11_BYTE_PROG_ADD_TYP_TIME_UNIT_S)
#define BFPT_DW11_BYTE_PROG_ADD_TYP_TIME_S			19
#define BFPT_DW11_BYTE_PROG_ADD_TYP_TIME_M			BITS(22, BFPT_DW11_BYTE_PROG_ADD_TYP_TIME_S)
#define BFPT_DW11_BYTE_PROG_1ST_TYP_TIME_UNIT_S			18
#define BFPT_DW11_BYTE_PROG_1ST_TYP_TIME_UNIT_M			BIT(BFPT_DW11_BYTE_PROG_1ST_TYP_TIME_UNIT_S)
#define BFPT_DW11_BYTE_PROG_1ST_TYP_TIME_S			14
#define BFPT_DW11_BYTE_PROG_1ST_TYP_TIME_M			BITS(17, BFPT_DW11_BYTE_PROG_1ST_TYP_TIME_S)
#define BFPT_DW11_PAGE_PROG_TYP_TIME_UNIT_S			13
#define BFPT_DW11_PAGE_PROG_TYP_TIME_UNIT_M			BIT(BFPT_DW11_PAGE_PROG_TYP_TIME_UNIT_S)
#define BFPT_DW11_PAGE_PROG_TYP_TIME_S				8
#define BFPT_DW11_PAGE_PROG_TYP_TIME_M				BITS(12, BFPT_DW11_PAGE_PROG_TYP_TIME_S)
#define BFPT_DW11_PAGE_SIZE_SHIFT_S				4
#define BFPT_DW11_PAGE_SIZE_SHIFT_M				BITS(7, BFPT_DW11_PAGE_SIZE_SHIFT_S)
#define BFPT_DW11_PAGE_BYTE_PROG_MAX_TIME_MULTIPLIER_S		0
#define BFPT_DW11_PAGE_BYTE_PROG_MAX_TIME_MULTIPLIER_M		BITS(3, BFPT_DW11_PAGE_BYTE_PROG_MAX_TIME_MULTIPLIER_S)

/* DWORD11 Chip typical erase time unit */
#define DW11_CHIP_ERASE_TYP_TIME_UNIT_16MS			0
#define DW11_CHIP_ERASE_TYP_TIME_UNIT_256MS			1
#define DW11_CHIP_ERASE_TYP_TIME_UNIT_4S			2
#define DW11_CHIP_ERASE_TYP_TIME_UNIT_64S			3

/* DWORD11 Byte program typical time unit */
#define DW11_BYTE_PROG_TYP_TIME_UNIT_1US			0
#define DW11_BYTE_PROG_TYP_TIME_UNIT_8US			1

/* DWORD11 Page program typical time unit */
#define DW11_PAGE_PROG_TYP_TIME_UNIT_8US			0
#define DW11_PAGE_PROG_TYP_TIME_UNIT_64US			1

/* Basic Flash Parameter Table DWORD 12 */
#define BFPT_DW12_SUPPORT_SUSPEND_RESUME			BIT(31)
#define BFPT_DW12_SUSPEND_OIP_ERASE_MAX_LATENCY_UNIT_S		29
#define BFPT_DW12_SUSPEND_OIP_ERASE_MAX_LATENCY_UNIT_M		BITS(30, BFPT_DW12_SUSPEND_OIP_ERASE_MAX_LATENCY_UNIT_S)
#define BFPT_DW12_SUSPEND_OIP_ERASE_MAX_LATENCY_S		24
#define BFPT_DW12_SUSPEND_OIP_ERASE_MAX_LATENCY_M		BITS(28, BFPT_DW12_SUSPEND_OIP_ERASE_MAX_LATENCY_S)
#define BFPT_DW12_ERASE_RESUME_TO_SUSPEND_INTERVAL_S		20
#define BFPT_DW12_ERASE_RESUME_TO_SUSPEND_INTERVAL_M		BITS(23, BFPT_DW12_ERASE_RESUME_TO_SUSPEND_INTERVAL_S)
#define BFPT_DW12_SUSPEND_OIP_PROG_MAX_LATENCY_UNIT_S		18
#define BFPT_DW12_SUSPEND_OIP_PROG_MAX_LATENCY_UNIT_M		BITS(19, BFPT_DW12_SUSPEND_OIP_PROG_MAX_LATENCY_UNIT_S)
#define BFPT_DW12_SUSPEND_OIP_PROG_MAX_LATENCY_S		13
#define BFPT_DW12_SUSPEND_OIP_PROG_MAX_LATENCY_M		BITS(17, BFPT_DW12_SUSPEND_OIP_PROG_MAX_LATENCY_S)
#define BFPT_DW12_PROG_RESUME_TO_SUSPEND_INTERVAL_S		9
#define BFPT_DW12_PROG_RESUME_TO_SUSPEND_INTERVAL_M		BITS(12, BFPT_DW12_PROG_RESUME_TO_SUSPEND_INTERVAL_S)
#define BFPT_DW12_ERASE_SUSPEND_PROHIBITED_OPS_S		4
#define BFPT_DW12_ERASE_SUSPEND_PROHIBITED_OPS_M		BITS(7, BFPT_DW12_ERASE_SUSPEND_PROHIBITED_OPS_S)
#define BFPT_DW12_PROG_SUSPEND_PROHIBITED_OPS_S			0
#define BFPT_DW12_PROG_SUSPEND_PROHIBITED_OPS_M			BITS(3, BFPT_DW12_PROG_SUSPEND_PROHIBITED_OPS_S)

/* DWORD12 Suspend in-progress erase/program max latency unit */
#define DW12_SUSPEND_OIP_EP_MAX_LATENCY_UNIT_128NS		0
#define DW12_SUSPEND_OIP_EP_MAX_LATENCY_UNIT_1US		1
#define DW12_SUSPEND_OIP_EP_MAX_LATENCY_UNIT_8US		2
#define DW12_SUSPEND_OIP_EP_MAX_LATENCY_UNIT_64US		3

/* Basic Flash Parameter Table DWORD 13 */
#define BFPT_DW13_SUSPEND_OPCODE_S				24
#define BFPT_DW13_SUSPEND_OPCODE_M				BITS(31, BFPT_DW13_SUSPEND_OPCODE_S)
#define BFPT_DW13_RESUME_OPCODE_S				16
#define BFPT_DW13_RESUME_OPCODE_M				BITS(23, BFPT_DW13_RESUME_OPCODE_S)
#define BFPT_DW13_PROG_SUSPEND_OPCODE_S				8
#define BFPT_DW13_PROG_SUSPEND_OPCODE_M				BITS(15, BFPT_DW13_PROG_SUSPEND_OPCODE_S)
#define BFPT_DW13_PROG_SRESUME_OPCODE_S				0
#define BFPT_DW13_PROG_SRESUME_OPCODE_M				BITS(7, BFPT_DW13_PROG_SRESUME_OPCODE_S)

/* Basic Flash Parameter Table DWORD 14 */
#define BFPT_DW14_DEEP_POWERDOWN_SUPPORTED			BIT(31)
#define BFPT_DW14_ENTER_DPD_OPCODE_S				23
#define BFPT_DW14_ENTER_DPD_OPCODE_M				BITS(30, BFPT_DW14_ENTER_DPD_OPCODE_S)
#define BFPT_DW14_EXIT_DPD_OPCODE_S				15
#define BFPT_DW14_EXIT_DPD_OPCODE_M				BITS(22, BFPT_DW14_EXIT_DPD_OPCODE_S)
#define BFPT_DW14_EXIT_DPD_TO_NEXT_OP_DELAY_UNIT_S		13
#define BFPT_DW14_EXIT_DPD_TO_NEXT_OP_DELAY_UNIT_M		BITS(14, BFPT_DW14_EXIT_DPD_TO_NEXT_OP_DELAY_UNIT_S)
#define BFPT_DW14_EXIT_DPD_TO_NEXT_OP_DELAY_S			8
#define BFPT_DW14_EXIT_DPD_TO_NEXT_OP_DELAY_M			BITS(12, BFPT_DW14_EXIT_DPD_TO_NEXT_OP_DELAY_S)
#define BFPT_DW14_SR_POLLING_DEV_BUSY_S				2
#define BFPT_DW14_SR_POLLING_DEV_BUSY_M				BITS(7, BFPT_DW14_SR_POLLING_DEV_BUSY_S)

/* DWORD14 Exit Deep Powerdown to next operation delay unit */
#define DW14_EXIT_DPD_TO_NEXT_OP_DELAY_UNIT_128NS		0
#define DW14_EXIT_DPD_TO_NEXT_OP_DELAY_UNIT_1US			1
#define DW14_EXIT_DPD_TO_NEXT_OP_DELAY_UNIT_8US			2
#define DW14_EXIT_DPD_TO_NEXT_OP_DELAY_UNIT_64US		3

/* Basic Flash Parameter Table DWORD 15 */
#define BFPT_DW15_HOLD_WP_DISABLE				BIT(23)
#define BFPT_DW15_QE_REQ_S					20
#define BFPT_DW15_QE_REQ_M					BITS(22, BFPT_DW15_QE_REQ_S)
#define BFPT_DW15_0_4_4_ENTRY_METHOD_S				16
#define BFPT_DW15_0_4_4_ENTRY_METHOD_M				BITS(19, BFPT_DW15_0_4_4_ENTRY_METHOD_S)
#define BFPT_DW15_0_4_4_EXIT_METHOD_S				10
#define BFPT_DW15_0_4_4_EXIT_METHOD_M				BITS(15, BFPT_DW15_0_4_4_EXIT_METHOD_S)
#define BFPT_DW15_0_4_4_SUPPORTED				BIT(9)
#define BFPT_DW15_4S_4S_4S_EN_SEQ_S				4
#define BFPT_DW15_4S_4S_4S_EN_SEQ_M				BITS(8, BFPT_DW15_4S_4S_4S_EN_SEQ_S)
#define BFPT_DW15_4S_4S_4S_DIS_SEQ_S				0
#define BFPT_DW15_4S_4S_4S_DIS_SEQ_M				BITS(3, BFPT_DW15_4S_4S_4S_DIS_SEQ_S)

/* DWORD15 Quad Enable Requirements */
#define DW15_QE_REQ_NONE					0
#define DW15_QE_REQ_SR2_BIT1_WR_SR1				1
#define DW15_QE_REQ_SR1_BIT6					2
#define DW15_QE_REQ_SR2_BIT7					3
#define DW15_QE_REQ_SR2_BIT1_WR_SR1_NC				4
#define DW15_QE_REQ_SR2_BIT1_WR_SR1_05H_35H_01H			5
#define DW15_QE_REQ_SR2_BIT1					6

/* DWORD15 4S-4S-4S mode enable sequences */
#define DW15_4S_4S_4S_EN_SEQ_QER_38H				BIT(0)
#define DW15_4S_4S_4S_EN_SEQ_38H				BIT(1)
#define DW15_4S_4S_4S_EN_SEQ_35H				BIT(2)
#define DW15_4S_4S_4S_EN_SEQ_800003H				BIT(3)
#define DW15_4S_4S_4S_EN_SEQ_VECR				BIT(4)	/*  Supported since JESD216B */

/* DWORD15 4S-4S-4S mode disable sequences */
#define DW15_4S_4S_4S_DIS_SEQ_FFH				BIT(0)
#define DW15_4S_4S_4S_DIS_SEQ_F5H				BIT(1)
#define DW15_4S_4S_4S_DIS_SEQ_800003H				BIT(2)
#define DW15_4S_4S_4S_DIS_SEQ_66H_99H				BIT(3)

/* Basic Flash Parameter Table DWORD 16 */
#define BFPT_DW16_ENTER_4B_CAPS_S				24
#define BFPT_DW16_ENTER_4B_CAPS_M				BITS(31, BFPT_DW16_ENTER_4B_CAPS_S)
#define BFPT_DW16_EXIT_4B_CAPS_S				14
#define BFPT_DW16_EXIT_4B_CAPS_M				BITS(23, BFPT_DW16_EXIT_4B_CAPS_S)
#define BFPT_DW16_SOFT_RESET_RESCUE_SEQ_CAPS_S			8
#define BFPT_DW16_SOFT_RESET_RESCUE_SEQ_CAPS_M			BITS(13, BFPT_DW16_SOFT_RESET_RESCUE_SEQ_CAPS_S)
#define BFPT_DW16_SR1_WR_NV_CAPS_S				0
#define BFPT_DW16_SR1_WR_NV_CAPS_M				BITS(6, BFPT_DW16_SR1_WR_NV_CAPS_S)

/* DWORD16 Enter 4-Byte Addressing method */
#define DW16_ENTER_4B_B7H					BIT(0)
#define DW16_ENTER_4B_WREN_B7H					BIT(1)
#define DW16_ENTER_4B_EAR					BIT(2)
#define DW16_ENTER_4B_BANK					BIT(3)
#define DW16_ENTER_4B_NVCR					BIT(4)
#define DW16_ENTER_4B_OPCODE					BIT(5)
#define DW16_ENTER_4B_ALWAYS					BIT(6)

/* DWORD16 Exit 4-Byte Addressing method */
#define DW16_EXIT_4B_E9H					BIT(0)
#define DW16_EXIT_4B_WREN_E9H					BIT(1)
#define DW16_EXIT_4B_EAR					BIT(2)
#define DW16_EXIT_4B_BANK					BIT(3)
#define DW16_EXIT_4B_NVCR					BIT(4)
#define DW16_EXIT_4B_HW_RESET					BIT(5)
#define DW16_EXIT_4B_SOFT_RESET					BIT(6)
#define DW16_EXIT_4B_POWER_CYCLE				BIT(7)

/* DWORD16 Soft Reset and Rescue Sequence Support */
#define DW16_SOFT_RESET_SEQ_DRIVE_FH_4IO_8CLKS			BIT(0)
#define DW16_SOFT_RESET_SEQ_4B_MODE_DRIVE_FH_4IO_10CLKS		BIT(1)
#define DW16_SOFT_RESET_SEQ_DRIVE_FH_4IO_16CLKS			BIT(2)
#define DW16_SOFT_RESET_SEQ_F0H					BIT(3)
#define DW16_SOFT_RESET_SEQ_66H_99H				BIT(4)
#define DW16_SOFT_RESET_EXIT_0_4_4_REQUIRED			BIT(5)

/* DWORD16 Volatile or Non-Volatile Register and Write Enable Instruction for Status Register 1 */
#define DW16_SR1_NV_PWR_LAST_WREN_06H_REQ			BIT(0)
#define DW16_SR1_V_PWR_ALL_1_WREN_06H_REQ			BIT(1)
#define DW16_SR1_V_PWR_ALL_1_WREN_50H_REQ			BIT(2)
#define DW16_SR1_NV_V_PWR_LAST_NV_WREN_06H_V_WREN_50H_REQ	BIT(3)
#define DW16_SR1_MIXED_WREN_06H_REQ				BIT(4)

/* Basic Flash Parameter Table DWORD 17 (Ssupported since JESD216C) */
#define BFPT_DW17_1S_1S_8S_FAST_READ_OPCODE_S			24
#define BFPT_DW17_1S_1S_8S_FAST_READ_OPCODE_M			BITS(31, BFPT_DW17_1S_1S_8S_FAST_READ_OPCODE_S)
#define BFPT_DW17_1S_1S_8S_FAST_READ_MODE_CLKS_S		21
#define BFPT_DW17_1S_1S_8S_FAST_READ_MODE_CLKS_M		BITS(23, BFPT_DW17_1S_1S_8S_FAST_READ_MODE_CLKS_S)
#define BFPT_DW17_1S_1S_8S_FAST_READ_DUMMY_CLKS_S		16
#define BFPT_DW17_1S_1S_8S_FAST_READ_DUMMY_CLKS_M		BITS(20, BFPT_DW17_1S_1S_8S_FAST_READ_DUMMY_CLKS_S)
#define BFPT_DW17_1S_8S_8S_FAST_READ_OPCODE_S			8
#define BFPT_DW17_1S_8S_8S_FAST_READ_OPCODE_M			BITS(15, BFPT_DW17_1S_8S_8S_FAST_READ_OPCODE_S)
#define BFPT_DW17_1S_8S_8S_FAST_READ_MODE_CLKS_S		5
#define BFPT_DW17_1S_8S_8S_FAST_READ_MODE_CLKS_M		BITS(7, BFPT_DW17_1S_8S_8S_FAST_READ_MODE_CLKS_S)
#define BFPT_DW17_1S_8S_8S_FAST_READ_DUMMY_CLKS_S		0
#define BFPT_DW17_1S_8S_8S_FAST_READ_DUMMY_CLKS_M		BITS(4, BFPT_DW17_1S_8S_8S_FAST_READ_DUMMY_CLKS_S)

/* Basic Flash Parameter Table DWORD 18 */
#define BFPT_DW18_OCTAL_DTR_BYTE_ORDER				BIT(31)
#define BFPT_DW18_OCTAL_DTR_CMD_EXT_S				29
#define BFPT_DW18_OCTAL_DTR_CMD_EXT_M				BITS(30, BFPT_DW18_OCTAL_DTR_CMD_EXT_S)
#define BFPT_DW18_DS_FOR_QPI_DTR_MODE				BIT(27)
#define BFPT_DW18_DS_FOR_QPI_STR_MODE				BIT(26)
#define BFPT_DW18_DS_WAVEFORM_STR_MODE_S			24
#define BFPT_DW18_DS_WAVEFORM_STR_MODE_M			BITS(25, BFPT_DW18_DS_WAVEFORM_STR_MODE_S)
#define BFPT_DW18_JEDEC_SPI_PROTO_RESET				BIT(23)
#define BFPT_DW18_VARIABLE_OUTPUT_DRIVER_STRENGTH_S		18
#define BFPT_DW18_VARIABLE_OUTPUT_DRIVER_STRENGTH_M		BITS(22, BFPT_DW18_VARIABLE_OUTPUT_DRIVER_STRENGTH_S)

/* Basic Flash Parameter Table DWORD 19 */
#define BFPT_DW19_OE_REQ_S					20
#define BFPT_DW19_OE_REQ_M					BITS(22, BFPT_DW19_OE_REQ_S)
#define BFPT_DW19_0_8_8_ENTRY_METHOD_S				16
#define BFPT_DW19_0_8_8_ENTRY_METHOD_M				BITS(19, BFPT_DW19_0_8_8_ENTRY_METHOD_S)
#define BFPT_DW19_0_8_8_EXIT_METHOD_S				10
#define BFPT_DW19_0_8_8_EXIT_METHOD_M				BITS(15, BFPT_DW19_0_8_8_EXIT_METHOD_S)
#define BFPT_DW19_0_8_8_SUPPORTED				BIT(9)
#define BFPT_DW19_8S_8S_8S_EN_SEQ_S				4
#define BFPT_DW19_8S_8S_8S_EN_SEQ_M				BITS(8, BFPT_DW19_8S_8S_8S_EN_SEQ_S)
#define BFPT_DW19_8S_8S_8S_DIS_SEQ_S				0
#define BFPT_DW19_8S_8S_8S_DIS_SEQ_M				BITS(3, BFPT_DW19_8S_8S_8S_DIS_SEQ_S)

/* Basic Flash Parameter Table DWORD 20 */
#define BFPT_DW20_MAX_SPEED_8D_8D_8D_DS_S			28
#define BFPT_DW20_MAX_SPEED_8D_8D_8D_DS_M			BITS(31, BFPT_DW20_MAX_SPEED_8D_8D_8D_DS_S)
#define BFPT_DW20_MAX_SPEED_8D_8D_8D_NO_DS_S			24
#define BFPT_DW20_MAX_SPEED_8D_8D_8D_NO_DS_M			BITS(27, BFPT_DW20_MAX_SPEED_8D_8D_8D_NO_DS_S)
#define BFPT_DW20_MAX_SPEED_8S_8S_8S_DS_S			20
#define BFPT_DW20_MAX_SPEED_8S_8S_8S_DS_M			BITS(23, BFPT_DW20_MAX_SPEED_8S_8S_8S_DS_S)
#define BFPT_DW20_MAX_SPEED_8S_8S_8S_NO_DS_S			16
#define BFPT_DW20_MAX_SPEED_8S_8S_8S_NO_DS_M			BITS(19, BFPT_DW20_MAX_SPEED_8S_8S_8S_NO_DS_S)
#define BFPT_DW20_MAX_SPEED_4D_4D_4D_DS_S			12
#define BFPT_DW20_MAX_SPEED_4D_4D_4D_DS_M			BITS(15, BFPT_DW20_MAX_SPEED_4D_4D_4D_DS_S)
#define BFPT_DW20_MAX_SPEED_4D_4D_4D_NO_DS_S			8
#define BFPT_DW20_MAX_SPEED_4D_4D_4D_NO_DS_M			BITS(11, BFPT_DW20_MAX_SPEED_4D_4D_4D_NO_DS_S)
#define BFPT_DW20_MAX_SPEED_4S_4S_4S_DS_S			4
#define BFPT_DW20_MAX_SPEED_4S_4S_4S_DS_M			BITS(7, BFPT_DW20_MAX_SPEED_4S_4S_4S_DS_S)
#define BFPT_DW20_MAX_SPEED_4S_4S_4S_NO_DS_S			0
#define BFPT_DW20_MAX_SPEED_4S_4S_4S_NO_DS_M			BITS(3, BFPT_DW20_MAX_SPEED_4S_4S_4S_NO_DS_S)

/* Basic Flash Parameter Table DWORD 21 (Ssupported since JESD216F) */
#define BFPT_DW21_SUPPORT_4S_4D_4D_FAST_READ			BIT(3)
#define BFPT_DW21_SUPPORT_1S_4D_4D_FAST_READ			BIT(2)
#define BFPT_DW21_SUPPORT_1S_2D_2D_FAST_READ			BIT(1)
#define BFPT_DW21_SUPPORT_1S_1D_1D_FAST_READ			BIT(0)

/* Basic Flash Parameter Table DWORD 22 */
#define BFPT_DW22_1S_2D_2D_FAST_READ_OPCODE_S			24
#define BFPT_DW22_1S_2D_2D_FAST_READ_OPCODE_M			BITS(31, BFPT_DW22_1S_2D_2D_FAST_READ_OPCODE_S)
#define BFPT_DW22_1S_2D_2D_FAST_READ_MODE_CLKS_S		21
#define BFPT_DW22_1S_2D_2D_FAST_READ_MODE_CLKS_M		BITS(23, BFPT_DW22_1S_2D_2D_FAST_READ_MODE_CLKS_S)
#define BFPT_DW22_1S_2D_2D_FAST_READ_DUMMY_CLKS_S		16
#define BFPT_DW22_1S_2D_2D_FAST_READ_DUMMY_CLKS_M		BITS(20, BFPT_DW22_1S_2D_2D_FAST_READ_DUMMY_CLKS_S)
#define BFPT_DW22_1S_1D_1D_FAST_READ_OPCODE_S			8
#define BFPT_DW22_1S_1D_1D_FAST_READ_OPCODE_M			BITS(15, BFPT_DW22_1S_1D_1D_FAST_READ_OPCODE_S)
#define BFPT_DW22_1S_1D_1D_FAST_READ_MODE_CLKS_S		5
#define BFPT_DW22_1S_1D_1D_FAST_READ_MODE_CLKS_M		BITS(7, BFPT_DW22_1S_1D_1D_FAST_READ_MODE_CLKS_S)
#define BFPT_DW22_1S_1D_1D_FAST_READ_DUMMY_CLKS_S		0
#define BFPT_DW22_1S_1D_1D_FAST_READ_DUMMY_CLKS_M		BITS(4, BFPT_DW22_1S_1D_1D_FAST_READ_DUMMY_CLKS_S)

/* Basic Flash Parameter Table DWORD 23 */
#define BFPT_DW23_4S_4D_4D_FAST_READ_OPCODE_S			24
#define BFPT_DW23_4S_4D_4D_FAST_READ_OPCODE_M			BITS(31, BFPT_DW23_4S_4D_4D_FAST_READ_OPCODE_S)
#define BFPT_DW23_4S_4D_4D_FAST_READ_MODE_CLKS_S		21
#define BFPT_DW23_4S_4D_4D_FAST_READ_MODE_CLKS_M		BITS(23, BFPT_DW23_4S_4D_4D_FAST_READ_MODE_CLKS_S)
#define BFPT_DW23_4S_4D_4D_FAST_READ_DUMMY_CLKS_S		16
#define BFPT_DW23_4S_4D_4D_FAST_READ_DUMMY_CLKS_M		BITS(20, BFPT_DW23_4S_4D_4D_FAST_READ_DUMMY_CLKS_S)
#define BFPT_DW23_1S_4D_4D_FAST_READ_OPCODE_S			8
#define BFPT_DW23_1S_4D_4D_FAST_READ_OPCODE_M			BITS(15, BFPT_DW23_1S_4D_4D_FAST_READ_OPCODE_S)
#define BFPT_DW23_1S_4D_4D_FAST_READ_MODE_CLKS_S		5
#define BFPT_DW23_1S_4D_4D_FAST_READ_MODE_CLKS_M		BITS(7, BFPT_DW23_1S_4D_4D_FAST_READ_MODE_CLKS_S)
#define BFPT_DW23_1S_4D_4D_FAST_READ_DUMMY_CLKS_S		0
#define BFPT_DW23_1S_4D_4D_FAST_READ_DUMMY_CLKS_M		BITS(4, BFPT_DW23_1S_4D_4D_FAST_READ_DUMMY_CLKS_S)

/* 4-byte Address Instruction Table DWORD 1 */
#define A4BIT_DW1_SUPPORT_1S_8S_8S_PAGE_PROG			BIT(24)
#define A4BIT_DW1_SUPPORT_1S_1S_8S_PAGE_PROG			BIT(23)
#define A4BIT_DW1_SUPPORT_1S_8D_8D_READ				BIT(22)
#define A4BIT_DW1_SUPPORT_1S_8S_8S_FAST_READ			BIT(21)
#define A4BIT_DW1_SUPPORT_1S_1S_8S_FAST_READ			BIT(20)
#define A4BIT_DW1_SUPPORT_NON_VOLATILE_INDIV_SERC_LOCK_W	BIT(19)
#define A4BIT_DW1_SUPPORT_NON_VOLATILE_INDIV_SERC_LOCK_R	BIT(18)
#define A4BIT_DW1_SUPPORT_VOLATILE_INDIV_SERC_LOCK_W		BIT(17)
#define A4BIT_DW1_SUPPORT_VOLATILE_INDIV_SERC_LOCK_R		BIT(16)
#define A4BIT_DW1_SUPPORT_1S_4D_4D_READ				BIT(15)
#define A4BIT_DW1_SUPPORT_1S_2D_2D_READ				BIT(14)
#define A4BIT_DW1_SUPPORT_1S_1D_1D_READ				BIT(13)
#define A4BIT_DW1_SUPPORT_ERASE_T4				BIT(12)
#define A4BIT_DW1_SUPPORT_ERASE_T3				BIT(11)
#define A4BIT_DW1_SUPPORT_ERASE_T2				BIT(10)
#define A4BIT_DW1_SUPPORT_ERASE_T1				BIT(9)
#define A4BIT_DW1_SUPPORT_1S_4S_4S_PAGE_PROG			BIT(8)
#define A4BIT_DW1_SUPPORT_1S_1S_4S_PAGE_PROG			BIT(7)
#define A4BIT_DW1_SUPPORT_1S_1S_1S_PAGE_PROG			BIT(6)
#define A4BIT_DW1_SUPPORT_1S_4S_4S_FAST_READ			BIT(5)
#define A4BIT_DW1_SUPPORT_1S_1S_4S_FAST_READ			BIT(4)
#define A4BIT_DW1_SUPPORT_1S_2S_2S_FAST_READ			BIT(3)
#define A4BIT_DW1_SUPPORT_1S_1S_2S_FAST_READ			BIT(2)
#define A4BIT_DW1_SUPPORT_1S_1S_1S_FAST_READ			BIT(1)
#define A4BIT_DW1_SUPPORT_1S_1S_1S_READ				BIT(0)

/* 4-byte Address Instruction Table DWORD 2 */
#define A4BIT_DW2_ERASE_TYPE4_OPCODE_S				24
#define A4BIT_DW2_ERASE_TYPE4_OPCODE_M				BITS(31, A4BIT_DW2_ERASE_TYPE4_OPCODE_S)
#define A4BIT_DW2_ERASE_TYPE3_OPCODE_S				16
#define A4BIT_DW2_ERASE_TYPE3_OPCODE_M				BITS(23, A4BIT_DW2_ERASE_TYPE3_OPCODE_S)
#define A4BIT_DW2_ERASE_TYPE2_OPCODE_S				8
#define A4BIT_DW2_ERASE_TYPE2_OPCODE_M				BITS(15, A4BIT_DW2_ERASE_TYPE2_OPCODE_S)
#define A4BIT_DW2_ERASE_TYPE1_OPCODE_S				0
#define A4BIT_DW2_ERASE_TYPE1_OPCODE_M				BITS(7, A4BIT_DW2_ERASE_TYPE1_OPCODE_S)

/* Sector Map Parameter Table DWORD 1 Common definitions */
#define SMPT_DW1_DESCRIPTOR_TYPE				BIT(1)
#define SMPT_DW1_SEQ_END_INDICATOR				BIT(0)

/* DWORD1 Descriptor Type */
#define SMPT_DESCRIPTOR_COMMAND					0
#define SMPT_DESCRIPTOR_MAP					1

/* Sector Map Parameter Table Configuration Detection Command Descriptor DWORD 1 */
#define SMPT_CMD_DW1_READ_DATA_MASK_S				24
#define SMPT_CMD_DW1_READ_DATA_MASK_M				BITS(31, SMPT_CMD_DW1_ADDRESS_LENGTH_S)
#define SMPT_CMD_DW1_ADDRESS_LENGTH_S				22
#define SMPT_CMD_DW1_ADDRESS_LENGTH_M				BITS(23, SMPT_CMD_DW1_ADDRESS_LENGTH_S)
#define SMPT_CMD_DW1_DUMMY_CLKS_S				16
#define SMPT_CMD_DW1_DUMMY_CLKS_M				BITS(19, SMPT_CMD_DW1_DUMMY_CLKS_S)
#define SMPT_CMD_DW1_DETECTION_OPCODE_S				8
#define SMPT_CMD_DW1_DETECTION_OPCODE_M				BITS(15, SMPT_CMD_DW1_DETECTION_OPCODE_S)

/* Sector Map Parameter Table Configuration Detection Command Descriptor DWORD 2 */
#define SMPT_CMD_DW2_DETECTION_ADDRESS_S			0
#define SMPT_CMD_DW2_DETECTION_ADDRESS_M			BITS(31, SMPT_CMD_DW2_DETECTION_ADDRESS_S)

/* Configuration Detection Command Descriptor DWORD1 Address Length */
#define CMD_DW1_NO_ADDRESS					0
#define CMD_DW1_3B_ADDRESS					1
#define CMD_DW1_4B_ADDRESS					2
#define CMD_DW1_VARIABLE_ADDRESS				3

/* Sector Map Parameter Table Configuration Map Descriptor Header DWORD */
#define SMPT_MAP_DW1_REGION_COUNT_S				16
#define SMPT_MAP_DW1_REGION_COUNT_M				BITS(23, SMPT_MAP_DW1_REGION_COUNT_S)
#define SMPT_MAP_DW1_CONFIGURATION_ID_S				8
#define SMPT_MAP_DW1_CONFIGURATION_ID_M				BITS(15, SMPT_MAP_DW1_CONFIGURATION_ID_S)

/* Sector Map Parameter Table Region DWORD */
#define SMPT_MAP_DW2_REGION_SIZE_S				8
#define SMPT_MAP_DW2_REGION_SIZE_M				BITS(31, SMPT_MAP_DW2_REGION_SIZE_S)
#define SMPT_MAP_DW2_ERASE_TYPE_4				BIT(3)
#define SMPT_MAP_DW2_ERASE_TYPE_3				BIT(2)
#define SMPT_MAP_DW2_ERASE_TYPE_2				BIT(1)
#define SMPT_MAP_DW2_ERASE_TYPE_1				BIT(0)
#define SMPT_MAP_DW2_ERASE_TYPE_MASK				BITS(3, 0)

#endif /* _UFPROG_SPI_NOR_SFDP_H_ */
